/*
 * jxUtils Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxUtils.lang;

import java.text.Normalizer;
import java.util.regex.Pattern;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxUtils
 * @package org.jxUtils.lang
 * @date 15/04/2014 - 13:53:41
 */
public final class StringUtil {
	
	/**
	 * @param value
	 * @return newValue
	 */
	public static final String normalize(final String value) {
	
		String newValue = Normalizer.normalize(value, Normalizer.Form.NFD);
		
		newValue = Pattern.compile("\\p{InCombiningDiacriticalMarks}+").matcher(newValue).replaceAll("");
		
		return newValue;
	}
	
	/**
	 * @param value
	 * @return newValue
	 */
	public static final String removePunctuation(final String value) {
	
		return value.replaceAll("\\p{Punct}", "");
	}
	
	/**
	 * @param value
	 * @return newValue
	 */
	public static final String removeSpace(final String value) {
	
		return value.replaceAll("\\p{Space}", "");
	}
	
	/**
	 * @param str
	 * @param value
	 * @param repeat
	 * @param before
	 * @return Returns the value <b>"value"</b> concatenated <b>"repeat"</b> times at the beginning or end of <b>"str"</b> in
	 *         accordance with the <b>"before"</b> parameter
	 */
	public static StringBuilder concat(final CharSequence str, final String value, final int repeat, final boolean before) {
	
		final StringBuilder newString = new StringBuilder(str);
		
		//
		for(int count = 0; count < repeat; count++) {
			
			//
			if(before) {
				
				newString.insert(0, value);
				
			}else {
				
				newString.append(value);
			}
		}
		
		return newString;
	}
}
